package com.flx.at.spring.code.apps.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;

/**
 * @Author: Fenglixiong
 * @Date: 2021/9/8 11:27
 * @Description: 自定义多播器，Spring的refresh方法中会先判断是否存在多播器，如果存在就不会继续创建
 *
 * if (beanFactory.containsLocalBean("applicationEventMulticaster")) {
 *    this.applicationEventMulticaster =
 *          beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class);
 * }
 * else {
 *    this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
 *    beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
 * }
 *
 */
@Slf4j
@Component("applicationEventMulticaster")
public class WorkMulticaster extends SimpleApplicationEventMulticaster {

    public WorkMulticaster(){
        log.info("Custom applicationEventMulticaster init...");
        this.setTaskExecutor(Executors.newSingleThreadExecutor());
    }

}
